<?php

namespace app\api\controller;
use think\Controller;
use think\Db;

class UserImgs extends Base
{
    public function __construct(){
        parent::__construct();
        $this->user=session('user');
    }

    //获取用户图片
    public function getUserImgs($name='',$type='',$pageNum=1,$pageSize=20)
    {
        $where=[];
        if($name!=''){
            $where['name']=['like','%'.$name.'%'];
        }
        if($type!=''){
            $where['type']=$type;
        }
        $where['owner']=$this->user['id'];
        $data = Db::name('imgs_user')->where($where)->page($pageNum,$pageSize)->select();
        $count = Db::name('imgs_user')->where($where)->count();
        return json(['code'=>200,'msg'=>'成功','data'=>$data,'count'=>$count,'success'=>true]);
    }
    //删除用户图片
    public function delUserImgs($id='')
    {
        if($id==''){
            return result(500,'id参数不能为空');
        }

        $where=[];
        $where['id']=$id;
        $where['owner']=$this->user['id'];

        $result = Db::name('imgs_user')->where($where)->delete();
        if(empty($result)){
            return result(500,'删除失败');
        }

        return result(200,'删除成功');
    }
}